#include <cstdio>

int n, t, s;

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("A.in", "r", stdin);
  freopen("A.out", "w", stdout);
#endif
#endif

  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &s);
    if (!s && !(n & 1)) puts("0");
    else
      printf("%d\n", ((n + 1) >> 1) - 1 + s);
  }
  return 0;
}